package com.sunop.pantiproblem.task;

import com.sunop.pantiproblem.model.ProblemDocument;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Component;

@Component
public class ProblemConsumer {
    @Autowired
    private ElasticsearchRepository esRepository;

    @RabbitListener(queues = "problem.queue")
    public void handleProblem(ProblemDocument problem) {
        // 将数据写入 Elasticsearch
        ProblemDocument doc = new ProblemDocument();
        doc.setPid(problem.getPid());
        doc.setTitle(problem.getTitle());
        doc.setContent(problem.getContent());
        esRepository.save(doc);
    }
}